package org.example.consts;

public class MySQLDataType {

    // 数值类型
    public static final String TINYINT = "TINYINT";
    public static final String SMALLINT = "SMALLINT";
    public static final String MEDIUMINT = "MEDIUMINT";
    public static final String INT = "INT";
    public static final String INTEGER = "INTEGER";
    public static final String BIGINT = "BIGINT";
    public static final String FLOAT = "FLOAT";
    public static final String DOUBLE = "DOUBLE";
    public static final String DECIMAL = "DECIMAL";

    // 日期和时间类型
    public static final String DATE = "DATE";
    public static final String DATETIME = "DATETIME";
    public static final String TIMESTAMP = "TIMESTAMP";
    public static final String TIME = "TIME";
    public static final String YEAR = "YEAR";

    // 字符串类型
    public static final String CHAR = "CHAR";
    public static final String VARCHAR = "VARCHAR";
    public static final String BINARY = "BINARY";
    public static final String VARBINARY = "VARBINARY";
    public static final String TINYBLOB = "TINYBLOB";
    public static final String BLOB = "BLOB";
    public static final String MEDIUMBLOB = "MEDIUMBLOB";
    public static final String LONGBLOB = "LONGBLOB";
    public static final String TINYTEXT = "TINYTEXT";
    public static final String TEXT = "TEXT";
    public static final String MEDIUMTEXT = "MEDIUMTEXT";
    public static final String LONGTEXT = "LONGTEXT";
    public static final String ENUM = "ENUM";
    public static final String SET = "SET";

    /**
     * 判断给定的数据类型在建表时是否需要设置长度
     *
     * @param dataType 数据类型
     * @return 如果需要设置长度，返回true；否则返回false
     */
    public static boolean isLengthRequired(String dataType) {
        switch (dataType.toUpperCase()) {
            case CHAR:
            case VARCHAR:
            case BINARY:
            case VARBINARY:
            case TINYBLOB:
            case BLOB:
            case MEDIUMBLOB:
            case LONGBLOB:
            case TINYTEXT:
            case TEXT:
            case MEDIUMTEXT:
            case LONGTEXT:
            case ENUM:
            case SET:
                return true;
            case TINYINT:
            case SMALLINT:
            case MEDIUMINT:
            case INT:
            case INTEGER:
            case BIGINT:
            case FLOAT:
            case DOUBLE:
            case DECIMAL:
            case DATE:
            case DATETIME:
            case TIMESTAMP:
            case TIME:
            case YEAR:
            default:
                return false;
        }
    }
}
